<template>
  <div class="user">
    <div class="user-item">
      <div class="user-header">
        <img src="http://s.weituibao.com/1583583975067/user-graduate%20(1).png">
        <div class="user-desc">
          <span>昵称：{{name}}</span>
          <span>登录名：black-封</span>
          <span>个性签名：天下谁最帅，彪哥最帅.</span>
        </div>
      </div>

      <ul class="user-list">
        <li @click="$router.push('/myorder')">
          <span>我的订单</span>
          <van-icon name="arrow" />
        </li>
        <li @click="$router.push('/address')">
          <span>地址管理</span>
          <van-icon name="arrow" />
        </li>
        <li>
          <span>关于我们</span>
          <van-icon name="arrow" />
        </li>
        <li @click='outlogin'>
          <span>退出登录</span>
          <van-icon name="arrow" />
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { getAdress } from '../../api/adress'
export default {
  data() {
    return {
      name: '彪哥'
    }
  },
  methods: {
    outlogin() {
      this.$router.push('/login')
      localStorage.removeItem('goodsid')
      localStorage.removeItem('goodsinfo')
      localStorage.removeItem('userlist')
      localStorage.removeItem('adress')
      localStorage.removeItem('token')
    },
    async load() {
      const { userid, username } = JSON.parse(localStorage.userlist || '[]')
      if (username) {
        this.name = username
      }
      const adresslist = await getAdress(userid)
      localStorage.adress = JSON.stringify(adresslist.data)
    }
  },
  created() {
    this.load()
  }
}
</script>
<style lang="scss">
.user {
  .user-header {
    width: 94%;
    margin: 10px 10px 25px 10px;
    height: 122px;
    background: linear-gradient(90deg, #1baeae, #51c7c7);
    box-shadow: 0 2px 5px #269090;
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;

    img {
      width: 64px;
      height: 64px;
      border-radius: 50%;
    }

    .user-desc {
      width: 70%;
      display: flex;
      flex-direction: column;
      margin-left: 10px;

      span {
        color: white;
        padding: 3px 0;
      }
    }
  }

  .user-list {
    margin-top: 10px;
    padding: 0px 20px;

    li {
      height: 44px;
      line-height: 44px;
      border-bottom: 1px solid #e9e9e9;
      display: flex;
      justify-content: space-between;
      font-size: 15px;

      .van-icon {
        margin-top: 15px;
      }
    }
  }
}
</style>
